package com.xiangxiao.rpan.storage.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

/**
 * @ClassName ReturnUtils
 * @Auther admin
 * @Email 573768011@qq.com
 * @Date 2024/8/8 17:51
 */
public class ReturnUtils {
  private ReturnUtils() {
  }

  /**
   * 自定义状态码(响应码)以8位整形来表示
   */
  public static final int CODE_LENTH = 8;
  public static final String RESP_CODE = "respCode";
  public static final String RESP_MESSAGE = "respMessage";
  public static final String RESP_REMARK = "respRemark";
  public static final String DATA_STR = "data";
  public static final String DATAS_STR = "datas";
  /**
   * 后六位为0时，为成功
   */
  public static final String SUCCESS_RESULT = "000000";


  /**
   * 引擎服务的规则
   */
  public static final String ENGINE_SUCCESS_STATUS = "200";
  public static final String ENGINE_STATUS_STR = "status";
  public static final String ENGINE_REASON_STR = "reason";

  public static boolean result(String code) {
    if (StringUtils.isEmpty(code)) {
      return false;
    }
    if (CODE_LENTH != code.length()) {
      return false;
    }
    return SUCCESS_RESULT.equals(code.substring(2));
  }

  public static JSONObject getHystrixReturn(String code, String message, String mark) {
    JSONObject response = new JSONObject();
    response.put(RESP_CODE, code);
    response.put(RESP_MESSAGE, message);
    response.put(RESP_REMARK, mark);
    return response;
  }
}
